package com.magic.gre.mvp.presenter;

import com.google.gson.reflect.TypeToken;
import com.magic.gre.entity.base.BaseObjectModel;
import com.magic.gre.mvp.contract.SmsCodeContract;
import com.magic.gre.mvp.model.SmsCodeModelImpl;
import com.noname.lib_base_java.mvp.BasePresenterImpl;

/**
 * Author: Lmoumou
 * Date: 2019-01-15 10:42
 * 文件名: SmsCodePresenterImpl
 * 描述:
 */
public class SmsCodePresenterImpl extends BasePresenterImpl<SmsCodeContract.View, SmsCodeContract.Model>
        implements SmsCodeContract.Presenter {
    public SmsCodePresenterImpl(SmsCodeContract.View view) {
        super(view);
    }

    @Override
    protected SmsCodeContract.Model creatModel() {
        return new SmsCodeModelImpl();
    }

    @Override
    public void pSmsCode(String phone,int type) {
        mModel.mSmsCode(new CommonObserver<BaseObjectModel<String>>(new TypeToken<BaseObjectModel<String>>(){}.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel<String> stringBaseObjectModel) {
                mView.vSmsCode(stringBaseObjectModel.body);
            }

            @Override
            public void onError(int status, String msg) {
                mView.doPrompt(msg);
                mView.hideLoadDialog();
            }
        },phone,type);
    }
}
